#include <liblut/io/ImgWriter.h>

#include <boost/algorithm/string.hpp>
#include <boost/gil/typedefs.hpp>
#include <boost/gil/extension/io_new/tiff_all.hpp>
#include <boost/gil/extension/io_new/png_all.hpp>
#include <boost/gil/extension/io_new/jpeg_all.hpp>



void saveImg(gil::rgb8_image_t::view_t img_view, fs::path output_name)
{
    std::string abs_path=fs::system_complete(output_name).string();
    #if BOOST_FILESYSTEM_VERSION < 3
    std::string lower_extension=output_name.extension();
    #else
    std::string lower_extension=output_name.extension().string();
    #endif

    std::cout<<" extension "<<lower_extension<<std::endl;
    to_lower(lower_extension);
    std::cout<<" lower extension "<<lower_extension<<std::endl;

    //---------------------------------------------------------
    if( (lower_extension==".tif")|| (lower_extension==".tiff") )
    {
        std::cout<<" tif "<<abs_path<<std::endl;
      gil::write_view( abs_path, img_view, gil::tiff_tag() );
      return;
    }
    if( (lower_extension==".jpeg")|| (lower_extension==".jpg") )
    {
        std::cout<<" jpeg "<<abs_path<<std::endl;
      gil::write_view( abs_path, img_view, gil::jpeg_tag() );
       return;
    }
    if( (lower_extension==".png") )
    {
        std::cout<<" png "<<abs_path<<std::endl;
      gil::write_view( abs_path, img_view, gil::png_tag() );
       return;
    }
     std::cout<<" no extension found "<<abs_path<<std::endl;
}


